package com.example.xiaozhi;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RecycleView extends AppCompatActivity {
List<AirCon> datas;
myAdapter myAdapter=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle_view);
        
        initDatas();

        RecyclerView recyclerView=findViewById(R.id.recyclerView);
        LinearLayoutManager manager =new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        myAdapter=new myAdapter(datas);
        recyclerView.setAdapter(myAdapter);
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));

    }
    private void initDatas() {
        datas=new ArrayList<>();
        AirCon airCon=new AirCon(this);
        airCon.setBrand("格力空调");
        airCon.setMode(AirCon.COLD);
        airCon.setMode1(AirCon.HWATER);
        airCon.setTemp(22);
        datas.add(airCon);
    }
//    private int counter=0;
public void addAirCon(View view) {
    AirCon airCon = new AirCon(this);
    int viewId = view.getId();
    if (viewId == R.id.btnkl) {
        airCon.setBrand("科龙空调");
        airCon.setMode(AirCon.COLD);
        airCon.setMode1(AirCon.KONGT);
        airCon.setTemp(26);
    } else if (viewId == R.id.btngl) {
        airCon.setBrand("格力空调");
        airCon.setMode(AirCon.COLD);
        airCon.setMode1(AirCon.HWATER);
        airCon.setTemp(22);
    } else if(viewId == R.id.btnoks) {
        airCon.setBrand("奥克斯空调");
        airCon.setMode(AirCon.COLD);
        airCon.setMode1(AirCon.ICE);
        airCon.setTemp(24);
    }
    // counter++; // 如果需要计数器，则取消注释这行代码，并确保定义了counter变量
    datas.add(airCon);
    myAdapter.notifyDataSetChanged();
}


}